import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path:'/',
    redirect:'/home/index'
    //重定向 : 跳转到home下的首页
  },
  {
    path: '/home',
    name: 'home',
    component: HomeView,

    children:[
        {
            path: 'index',
            name: '/home/index',
            component: ()=>import('../views/IndexView.vue'),
        },
        {
          path:'orderUpdate',
          name:'/home/orderUpdate',
          component:()=>import('../views/order/orderUpdate.vue')
        },
        {
          path:'order-list',
          name:'/home/order-list',
          component:()=>import('../views/order/orderList.vue')
        },
        {
          path:'user-list',
          name:'/home/user-list',
          component:()=>import('../views/user/userList.vue')
        },
        {
          path:'user-add',
          name:'/home/user-add',
          component:()=>import('../views/user/userAdd.vue')
        },
        {
          path:'user-update/:id',
          name:'/home/user-update',
          component:()=>import('../views/user/userUpdate.vue')
        },
        {
          path:'scenic-add',
          name:'/home/scenic-add',
          component:()=>import('../views/scenic/scenicAdd.vue')
        },
        {
          path:'scenicList',
          name:'/home/scenicList',
          component:()=>import('../views/scenic/scenicList.vue')
        },
        {
          path:'scenicUpdate',
          name:'/home/scenicUpdate',
          component:()=>import('../views/scenic/scenicUpdate.vue')
        },
        {
          path:'discussList',
          name:'/home/discussList',
          component:()=>import('../views/discussList.vue')
        },
        
    ]
    
  },
  {
    path:'/login',
    name:'login',
    component:()=>import('../views/admin/Login.vue')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
// 全局前置导航守卫
// import store from '../store'
router.beforeEach((to,from,next) => {
  // console.log('from:',from);
  // console.log('to:',to);
  if(to.path === '/login') {
    next()
  } else {
    if(localStorage.getItem('admin')) {
      next()
    } else {
      router.push('/login')
    }
  }
})
export default router
